import request from '@/utils/request'

/**
 * 为 PageRequestType 填充默认的分页参数 (index=1, size=15)
 * @param pageRequest
 */
function withDefaultPageParams(pageRequest) {
    const defaultedRequest = pageRequest ?? {
        model: {},
        page: {}
    }

    const { page = {} } = defaultedRequest

    return {
        ...defaultedRequest,
        model: defaultedRequest.model ?? {},
        page: {
            ...page,
            index: page.index ?? 1,
            size: page.size ?? 15
        }
    }
}

/**
 * 获取日志分页列表
 * @param pageRequest
 */
export function getLogPagesUrl(pageRequest = {}) {
    const defaultedPage = withDefaultPageParams(pageRequest)
    return request({
        url: '/system/log/findPage',
        method: 'post',
        data: defaultedPage
    })
}

/**
 * 获取日志详情
 * @param id 日志id
 */
export function getLogInfoByIdUrl(id) {
    return request({
        url: '/system/log/findByPk',
        method: 'get',
        params: {id}
    })
}

